/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * InputPlayerPanel.java
 *
 * Created on May 15, 2010, 3:01:34 PM
 */

package View.BuildMode;

import javax.swing.SpinnerNumberModel;

/**
 *
 * @author  Rezan Achmad
 *          13508104
 */
public class InputPlayerPanel extends javax.swing.JPanel {

    /** Creates new form InputPlayerPanel */
    public InputPlayerPanel(BuildMap parent) {
        initComponents();

        /* remember parent */
        this.parent = parent;

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        forplayerLabel = new javax.swing.JLabel();
        forplayerSpinner = new javax.swing.JSpinner();
        OKButton = new javax.swing.JButton();
        cancelButton = new javax.swing.JButton();

        forplayerLabel.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        forplayerLabel.setText("For Player");

        forplayerSpinner.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N

        OKButton.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        OKButton.setText("OK");
        OKButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                OKButtonActionPerformed(evt);
            }
        });

        cancelButton.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        cancelButton.setText("Cancel");
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(forplayerLabel)
                .addGap(18, 18, 18)
                .addComponent(forplayerSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(OKButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cancelButton)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(forplayerLabel)
                    .addComponent(forplayerSpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(OKButton)
                    .addComponent(cancelButton))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void OKButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OKButtonActionPerformed
        Integer i = (Integer)forplayerSpinner.getValue();
        parent.setPlayerbuilding(i);
        parent.UpdateBuilding(i, building);
        this.setVisible(false);
    }//GEN-LAST:event_OKButtonActionPerformed

    private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
        this.setVisible(false);
    }//GEN-LAST:event_cancelButtonActionPerformed

    public void update(int maxPlayer, String building) {
        /* Set spinner model */
        forplayerSpinner.setModel(new SpinnerNumberModel(1, 1, maxPlayer, 1));

        /* */
        this.building = building;
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton OKButton;
    private javax.swing.JButton cancelButton;
    private javax.swing.JLabel forplayerLabel;
    private javax.swing.JSpinner forplayerSpinner;
    // End of variables declaration//GEN-END:variables

    private BuildMap parent;
    private String building;
}
